package 分类.差分数组;

import java.util.Arrays;

public class 区间加法 {
    public int[] getModifiedArray(int length, int[][] updates) {
        int[] nums=new int[length];
        Arrays.fill(nums,0);
        int[] diff=new int[length];
        for (int[] update : updates) {
            int start=update[0];
            int end=update[1];
            int val=update[2];
            diff[start]+=val;
            if(end+1<length){
                diff[end+1]-=val;
            }
        }

        nums[0]=diff[0];
        for (int i=1;i<length;i++){
            nums[i]=diff[i]+nums[i-1];
        }
        return nums;
    }
}
